<template>
	<view class="container">
		<view class="jilu_list">
			<view class=" xiangmu" v-for="(item,index) in dataList" :key="index">
				<view class="list_title uni-flex uni-flex-align flex-bt">
					<view class=" uni-flex uni-flex-align ">
						<view class="left">
							<image :src="item.img_url" mode=""></image>
						</view>
						<view class="right">
							<view>{{item.subject}}</view>
							<view class="">{{tui.timestampToDateTime(item.start_time*1000)}}</view>
						</view>
					</view>
					<view class="">
						<tui-button width="120rpx" height="60rpx" type="danger" :size="24" @click="daoChu(item)">导出</tui-button>
					</view>
				</view>
				<!-- <view class="miaoshu" v-if="item.status==4">驳回原因: <text>{{item.remark}}</text></view> -->
			</view>
		</view>
		<view class="empty-box" v-if="dataList.length==0">
			<image src="/static/ic_nodata.png" mode=""></image>
			<view class="">暂无数据</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				dataList:[],
				type:'',
				m_type:'',
				id:'',
				uuid:'',
				timer:null,
			}
		},
		onLoad(e) {
			this.id = e.id
			this.getList()
			// 使用示例
			
		},
		onReachBottom() {
			this.page++
			this.getList()
		},
		methods: {
			getList(){
				let that = this
				that.tui.addrequest('live/list', "get",{page:that.page,page_size:20,tz_id:that.id}, false, false, true).then((res) => {
					if(res.code==0){
						that.dataList = that.dataList.concat(res.data)
					}
				}).catch((res) => {})
			},
			daoChu(e){
				let that = this
				that.tui.addrequest('live/tz/export/'+e.room_id+'/'+that.id, "get",{}, false, false, true).then((res) => {
					if(res.code==0){
						that.uuid = res.uuid
						that.timer = setTimeout(()=>{
							that.lunxun()
						},1000)
					}
				}).catch((res) => {})
			},
			fuzhi(e){
				let that = this
				uni.setClipboardData({
					data: e,
					success: function () {
					 that.tui.toast('复制成功,请打开浏览器下载',5000)
					},
				})
			},
			lunxun(){
				let that = this
				that.tui.addrequest('live/tz/export-result', "get",{uuid:that.uuid}, false, false, false).then((res) => {
					if(res.code==0){
						clearTimeout(that.timer)
						// window.location.href = res.data.link
						// that.tui.href('/pages/tuanzhang/yulan?url='+res.data.link)
						that.fuzhi(res.data.link)
						return
						const downloadTask = uni.downloadFile({
							url: res.data.link, //仅为示例，并非真实的资源
							success: (res) => {
								if (res.statusCode === 200) {
									console.log('下载成功');
									uni.saveFile({
										tempFilePath: res.tempFilePath,
										success: function(red) {
											console.log(red)
											uni.showToast({
												icon: 'none',
												mask: true,
												title: '文件已保存：' + red.savedFilePath, //保存路径
												duration: 3000,
											});
										}
									});
								}
							}
						});
						
						downloadTask.onProgressUpdate((res) => {
							console.log('下载进度' + res.progress);
							console.log('已经下载的数据长度' + res.totalBytesWritten);
							console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
							
							// 满足测试条件，取消下载任务。
							if (res.progress > 50) {
								downloadTask.abort();
							}
						});
					}
				}).catch((res) => {})
			},
			
			convertBeijingToUTC(beijingTime) {
			    return beijingTime.toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
			}
			 
			
		}
	}
</script>

<style lang="scss">
	page{background: #f7f7f7;}
	.jilu_list{padding-bottom: 10rpx;}
	.nojilu{padding-top: 30rpx;}
	.xiangmu{margin: 20rpx;padding: 30rpx;background: #fff;	
		.list_title{line-height: 60rpx;padding-bottom: 10rpx;
			.left{color: #999;
				image{width: 80rpx;height: 80rpx;margin-right: 10rpx;}
			}
			.right{}
		}
		.x_title{font-weight: bold;margin-bottom: 20rpx;}
		.list{height: 60rpx;
			.right{font-weight: bold;text-align: right;
				.green{font-size: 28rpx;}
				.grey{font-weight: 400;color: #999;}
			}
		}
		.miaoshu{margin-top: 10rpx;font-size: 24rpx;
			text{color: #07c160;;}
		}
	}
</style>
